<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %> 
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>拖车申请</title>
<jsp:include page="../../import.jsp" flush="true" />
<jsp:include page="../assParking/assParkCommon.jsp" flush="true" /><!-- 时间格式转换 -->
</head>
<body class="iframeBody">
<div class="Wrapper">
	<div class="searchArea">
		<!-- 搜索表单开始 -->
		<form id="searchBar">
			<div class="fieldset1 clearFix">
				<div class="FXBR">
					<div class="fieldBox">
						<div class="label">客户名称</div>
						<div class="field">
							<input type="text" id="cstNm" name="cstNm" class="ui-textbox" ligerui="width: 160" value="">
						</div>
					</div>
					<div class="fieldBox">
						<div class="label">合同编号</div>
						<div class="field">
							<input type="text" id="contNo" name="contNo" class="ui-textbox" ligerui="width: 160" value="">
						</div>
					</div>
					<div class="fieldBox">
						<div class="label">支付表号</div>
						<div class="field">
							<input type="text" id="paySchNo" name="paySchNo" class="ui-textbox" ligerui="width: 160" value="">
						</div>
					</div>
					<div class="fieldBox">
						<div class="label">逾期天数</div>
						<div class="field">
							<input type="text" id="minOverdueDay" name="minOverdueDay" class="ui-textbox" ligerui="width: 80" value="">
							至
							<input type="text" id="maxOverdueDay" name="maxOverdueDay" class="ui-textbox" ligerui="width: 80" value="">
						</div>
					</div>
					<div class="fieldBox">
						<div class="label">拖车状态</div>
						<div class="field">
							<select name="backStsCd" id="backStsCd" ligerui="width: 160">
								<option value="" seleted>请选择</option>
								<option value="0">未申请</option>
								<c:forEach items="${backStsList }" var="back">
									<option value="${back.key }">${back.value }</option>
								</c:forEach>
							</select>
						</div>
					</div>
				</div>
				
				<div class="clearFix"></div>
				
				<!-- 表单按钮 -->
				<div class="btnsBox formBtns notRight">
					<span id="searchBtn" class="sq-button-round">查询</span>
					<span id="clearBtn" class="sq-button-round">清空</span>
					<input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
					<%--<span id="downBtn" class="sq-button-round" onclick="downloadBtnEvent();">导出Excel</span>--%>
	            </div>
	            <!-- 逾期提醒 -->
				<div class="disp_right">
					<span>
						<font color="red"><i class="ico_flasher"></i>逾期90(含)天以上必须拖车</font>
					</span>
	            </div>
			</div>
		</form>
		<!-- 搜索表单结束 -->
	</div>
</div>

<!-- 列表显示块 -->
<div id="ligergrid1" class="sq-grid"></div>

<script type="text/javascript">
	var grid = null;
	$(function () {
	    initForm();//初始化表单
	    initGrid();//注意初始化要在initForm之后,因为在初始化grid的时候需要form参数
	    searchBtnEvent();//查询按钮事件
	    clearBtnEvent();//清空按钮事件
	});
	
	//初始化表单
	function initForm(){
		$("#searchBar").ligerForm();
	}
	
	//查询参数
	function getSearchParams(){
		var form = new liger.get("searchBar");
		var data = form.getData();
		return data;
	}
	
	//初始化列表
	function initGrid(){
		$("#ligergrid1").ligerGrid({
			url:'<%=path%>/ass/assTrailCarD/initList.do',
			method:'get',
			parms:getSearchParams(),
			columns:[
				{ display: '<span class="sqiconfont sqicon-tishi c_sqYellow gridTip" title="拖车提醒"></span>', 
					name: '', minWidth: 30 , align:'center', enabledSort:true,
					render: function (rowdata, rowindex, value, column) { 
						var h = '';
						if(rowdata.overdueDay>=90){//拖车提醒
							h = '<i class="ico_flasher"></i>';
						}
						return h;
					}},
				{ display: '支付表状态', name: 'payStatus', width: 100, enabledSort:true},
				{ display: '合同编号', name: 'contNo', minWidth: 180 , align:'center', enabledSort:true},
				{ display: '支付表号', name: 'paySchNo', minWidth: 180 , align:'center', enabledSort:true,
					render: function (rowdata, rowindex, value, column) { 
						var h = '';
						h='<a href="javascript:payDetail(';
                        h+="'"+rowdata.prjPrdDtlId+"',"; //项目产品明细信息表ID
                        h+="'"+rowdata.paySchId+"',"; //支付表ID
                        h+="'"+rowdata.prjPrdId+"',"; //项目产品基础信息表ID
                        h+="'"+rowdata.prjId+"'"; //项目基础信息表ID
						h+=')">'+value+'</a>';
						return h;
					}},
				{ display: '业务类型', name: 'businessType', width: 120, enabledSort:true},
				{ display: '客户名称', name: 'cstNm', width: 120 , enabledSort:true},
				{ display: '厂商', name: 'firm', width: 120, enabledSort:true},
				{ display: '经销商', name: 'splNm', width: 120, enabledSort:true},
				{ display: '事业部', name: 'orgName', width: 120, enabledSort:true},
				{ display: '逾期天数', name: 'overdueDay', width: 80 , enabledSort:true},
				{ display: '逾期租金(元)', name: 'overdueAmt', width: 100, align:'center', enabledSort:true,
					render: function (rowdata, rowindex, value, column) { 
						var h = 0;
		                h = rowdata.overdueAmt / 100;
						return h;
					}},
				{ display: '罚息金额(元)', name: 'penaltyAmt', width: 100, align:'center', enabledSort:true,
					render: function (rowdata, rowindex, value, column) { 
						var h = 0;
		                h = rowdata.penaltyAmt / 100;
						return h;
					}},
				{ display: '应付款总金额(元)', name: 'payAmt', width: 100, align:'center', enabledSort:true,
					render: function (rowdata, rowindex, value, column) { 
						var h = 0;
		                h = rowdata.payAmt / 100;
						return h;
					}},
				{ display: '拖车状态', name: 'backStsCd', width: 80, align:'center', enabledSort:true,
					render: function (rowdata, rowindex, value, column) { 
						var h = '未申请';
						if(rowdata.backStsCd != null){//拖车状态
							h = rowdata.backStsCd;
						}
						return h;
					}},
				{ display: '实付金额(元)', name: 'actualAmt', width: 100, align:'center', enabledSort:true,
					render: function (rowdata, rowindex, value, column) { 
						var h = 0;
		                h = rowdata.actualAmt / 100;
						return h;
					}},
				{ display: '保底价款(元)', name: 'baseAmt', width: 100, align:'center', enabledSort:true,
					render: function (rowdata, rowindex, value, column) { 
						var h = 0;
		                h = rowdata.baseAmt / 100;
						return h;
					}},
				getGridOperColumnContent()//操作列
			],
			pageSize:10,
			root:'rows',
			record:'total',
			hideLoadButton:false,
			width:'100%',
			height:'100%',
			heightDiff:-2,
			checkbox:true,//列表是否有选择框
			rownumbers:true//列表是否有行号
		});
		grid = liger.get("ligergrid1");
		grid.setHeight(100);
		grid.options.isSingleCheck = false;//列表是否为单选
	}
	
	//隐藏掉操作列
    function getGridOperColumnContent(){
		var data = {
			display:'操作',
			isSort:false,
			width:250,
			align:'center',
			render:function (rowdata, rowindex, value){
				var h="";
				if(rowdata.payStatus == "正常"){
	            	h+='<a class="sq-button-hasicon" href="javascript:trailCarApply(';
	                h+="'"+rowdata.paySchId+"'";
	                h+=",'"+rowdata.paySchNo+"'";
	                h+=",'"+rowdata.prjPrdDtlId+"'";
	                h+=",'"+rowdata.prjId+"'";
	                h+=",'"+rowdata.businessType+"'";
	                h+=",'"+rowdata.prjTypCd+"'";
	                h+=",'"+rowdata.prjNm+"'";
	                h+=",'"+rowdata.orgName+"'";
	                h+=",'"+rowdata.cstId+"'";
	                h+=",'"+rowdata.cstNm+"'";
	                h+=")\"><i class='sqBtnIco_4'></i>拖车申请</a>";
				}else{
                	h+='<font class="sq-button-hasicon" color="c9c9c9"><i class="sqBtnIco_4"></i>拖车申请</font>';
                }
				if(rowdata.backStsCd != null && rowdata.pNo != null){
	                h+='<a class="sq-button-hasicon" href="javascript:commShowFlow(';
	                h+="'"+rowdata.pinstId+"'";
	                h+=",'"+rowdata.audStsCd+"'";
	                h+=",'"+rowdata.masterId+"'";
	                h+=")\"><i class='sqBtnIco_32'></i>"+rowdata.pNo+"</a>";
				}
				return h;
			}
		};
		return data;
	}
	
	//清空按钮事件
	function clearBtnEvent(){
		$("#clearBtn").click(function(event) {
			$("#resetBtn").click();  //重置 input-text
			var form = liger.get("searchBar");
			form.setData({  //重置select等特殊表单
				"backStsCd":""
			});
		});
	}
	
	//查询按钮事件
	function searchBtnEvent(){
		$("#searchBtn").click(function(event) {
			var form = new liger.get("searchBar");
			var data = form.getData();
			for (name in data){
				grid.setParm(name,data[name]);
			};
			grid.reload();
		});
	}
	
	//查看支付表详情
	function payDetail(prjPrdDtlId,id,prjPrdId,prjId){
		var editFlag = true;
		Add_navTab('tab_prj_quat_prps'+id,'查看支付表','<%=path%>/project/prjprdpayschm/toAddPage.do?prjId='+prjId+'&&id='+id+'&&prjPrdDtlId='+prjPrdDtlId+'&&prjPrdId='+prjPrdId+'&&detailFlag='+editFlag);
	}
	
	//拖车申请
	function trailCarApply(paySchId,paySchNo,prjPrdDtlId,prjId,businessType,prjTypCd,prjNm,orgName,cstId,cstNm){
		//回调刷新列表
		var callback = function () {
			grid.reload();
		};
		var param = '&&prjPrdDtlId='+prjPrdDtlId+'&&prjId='+prjId+'&&businessType='+businessType;
		param += '&&prjTypCd='+prjTypCd+'&&prjNm='+prjNm+'&&orgName='+orgName+'&&cstId='+cstId+'&&cstNm='+cstNm;
		Add_navTab('trailCar'+paySchId,'拖车申请','<%=path%>/ass/assTrailCarD/toApplyPage.do?paySchId=' + paySchId + '&&paySchNo=' + paySchNo + param, callback);
	}
	
	//显示流程：流程实例ID,状态,业务主键(拖车主表ID)
    function commShowFlow(_pInstId, _audStsCd, _businessKey){
    	if(StringUtils.isEmpty(_pInstId)){
    		UIUtils.alertWarning(CommonConstant.C_P_INSTANCEID_NOT_HERE);
    		return;
    	}
    	var _formUrl = "/ass/assTrailCarM/toInfoViewPage.do?tcMasterId=";
    	var params = "?pInsId="+_pInstId+"&status="+_audStsCd+"&businessKey="+_businessKey+"&formUrl="+_formUrl;
    	Add_navTab('tab_ass_trail_flow_'+_businessKey,'查看流程',"<%=path%>/flow/flow/toFlowShowPageFowBus.do"+params);
    }
	
  	//导出信息
	function downloadBtnEvent(){
		var form = new liger.get("searchBar");
		var grid = liger.get("ligergrid1");
		var selectedRows = grid.getSelectedRows();
		var pkIds = new Array();
		for(var i=0;i<selectedRows.length;i++){
			var pkId = "'"+selectedRows[i].paySchId+"'";
			pkIds[i] = pkId;
		}
        var data = form.getData();
        data["pkIds"] = JSON.stringify(pkIds);
        data["eFlag"] = "tcsq";
		var wait_dialog = null;
		$.ajax({
			type: 'get',
			dataType:'json',
			url: '<%=path%>/ass/assTrailCarM/exportAssInfo.do',
			data:data,
			beforeSend:function(){
				wait_dialog=$.ligerDialog.SQalert({content: '正在导出信息...',SQ_type: "waitting"});
			},
			success:function(msg){
				wait_dialog.close();
				if(msg.success == 1){
					window.open(msg.data);
				}else{
					$.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
				}
			} 
		});
	}
	
</script>
</body>
</html>